package com.qf.day08.homework.arrsort;

import com.qf.day08.homework.fight.Hero;

import java.util.Arrays;

/**
 * 完成数组排序、
 * 数组中放的元素是自定义的对象
 */
public class Homework02 {

    public static void main(String[] args) {

        Hero[] heroes = new Hero[5];
        Hero hero1 = new Hero(100, 30);
        Hero hero2 = new Hero(90, 31);
        Hero hero3 = new Hero(80, 35);
        Hero hero4 = new Hero(120, 19);
        Hero hero5 = new Hero(130, 10);
        heroes[0] = hero1;
        heroes[1] = hero2;
        heroes[2] = hero3;
        heroes[3] = hero4;
        heroes[4] = hero5;

        // 对 heroes进行排序
        // com.qf.day08.homework.fight.Hero cannot be cast to java.lang.Comparable
        // 解决上面的异常，方案让 Hero实现 Comparable

        // 或者调用另外一个排序方法
//        Arrays.sort(heroes);
        // 需要准备一个 比较器对象，这个比较器对象能够比较两个Hero对象的大小关系
        HeroComparator heroComparator = new HeroComparator();
        Arrays.sort(heroes,heroComparator);


    }

}
